<template>
  <div class="personAssin">
    <h2>
      <span>成员分配</span>
      <span>
        <i class="el-icon-s-operation"></i>
      </span>
    </h2>

    <div class="personContent">
      <div
        class="personContentItem"
        v-for="(item, index) in person"
        :key="'item' + index"
      >
        <h2>{{ item[0] }}</h2>
        <ul>
          <li v-for="(it, ind) in item[1]" :key="'ite' + ind">
            <span>{{ it.name }}</span>
            <span>
              <el-rate v-model="it.score"></el-rate>
            </span>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { ReqListScorePro, ReqPersonByProjectId } from "../../../request";
export default {
  data() {
    return {
      person: [],
    };
  },
  methods: {
    // 获取项目
    async getProjectAccess() {
      const query = this.$router.history.current.query;
      console.log(query);
      const data = await ReqListScorePro({
        createdId: 1,
        scoredId: query.projectId,
      });
      const { scoreEntity } = data;
      if (scoreEntity && scoreEntity.scoreDetails) {
        this.person = JSON.parse(scoreEntity.scoreDetails).users;
        const map = new Map();
        this.person.forEach((item) => {
          if (map.has(item.position)) {
            map.get(item.position).push(item);
          } else {
            map.set(item.position, [item]);
          }
        });
        this.person = Array.from(map);
        console.log(this.person);
      } else {
        const query = this.$router.history.current.query;
        let resultData = await ReqPersonByProjectId(query);
        const { scoreVo } = resultData
        const map = new Map()
        scoreVo.forEach(item => {
          item.score = 0
          if(!map.has(item.position)) {
            map.set(item.position, [item])
          }else {
            map.get(item.position).push(item)
          }
        })
        const newArr = Array.from(map)
        this.person = newArr
      }
    },
  },
  async created() {
    await this.getProjectAccess();
  },
};
</script>

<style scoped>
.personAssin {
  width: 90%;
  margin: 20px auto;
}
.personAssin h2 {
  display: flex;
  line-height: 20px;
}
.personAssin h2 > :nth-child(n) {
  flex: 1;
}
.personAssin h2 > :nth-child(1) {
  text-align: left;
  font-size: 14px;
}
.personAssin h2 > :nth-child(2) {
  text-align: right;
  font-size: 20px;
}
.personContentItem {
  margin-top: 20px;
}
.personContentItem h2 {
  font-size: 14px;
}
.personContentItem ul li {
  display: flex;
  padding: 10px 0px;
  background: rgba(27, 147, 196, 0.16);
  margin: 5px;
  border-radius: 3px;
}
.personContentItem ul li > :nth-child(n) {
  flex: 1;
}
.personContentItem ul li > :nth-child(1) {
  padding-left: 20px;
  font-size: 14px;
}
.personContentItem ul li > :nth-child(2) {
  text-align: center;
}
.personContentItem ul li > :nth-child(3) {
  text-align: right;
  padding-right: 20px;
}
</style>
